package org.csu.bbs.controller;

import org.csu.bbs.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SectionController {
    @Autowired
    SectionService sectionServiceImpl;

    @GetMapping(value = {"api/sections" , "api/sections/{id}"})
    @CrossOrigin
    @ResponseBody
    public Object AllSection(@PathVariable(value = "id",required = false) Integer id){
        if(StringUtils.isEmpty(id)){
            return sectionServiceImpl.list();
        }else {
            return sectionServiceImpl.getById(id);
        }
    }
}
